import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  WarehousingVO,
  WarehousingForm,
  WarehousingQuery,
  WarehousingInfoForm,
  WarehousingInfoQuery,
  WarehousingInfoVO
} from '@/api/erp/warehousing/types';

/**
 * 查询采购入库列表
 * @param query
 * @returns {*}
 */

export const listWarehousing = (query?: WarehousingQuery): AxiosPromise<WarehousingVO[]> => {
  return request({
    url: '/erp/warehousing/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询采购入库详细
 * @param id
 */
export const getWarehousing = (id: string | number): AxiosPromise<WarehousingVO> => {
  return request({
    url: '/erp/warehousing/' + id,
    method: 'get'
  });
};

/**
 * 新增采购入库
 * @param data
 */
export const addWarehousing = (data: WarehousingForm) => {
  return request({
    url: '/erp/warehousing',
    method: 'post',
    data: data
  });
};

/**
 * 修改采购入库
 * @param data
 */
export const updateWarehousing = (data: WarehousingForm) => {
  return request({
    url: '/erp/warehousing',
    method: 'put',
    data: data
  });
};

/**
 * 删除采购入库
 * @param id
 */
export const delWarehousing = (id: string | number | Array<string | number>) => {
  return request({
    url: '/erp/warehousing/' + id,
    method: 'delete'
  });
};
/**
 * 查询入库明细列表
 * @param query
 * @returns {*}
 */

export const listWarehousingInfo = (query?: WarehousingInfoQuery): AxiosPromise<WarehousingInfoVO[]> => {
  return request({
    url: '/erp/warehousingInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询入库明细详细
 * @param id
 */
export const getWarehousingInfo = (id: string | number): AxiosPromise<WarehousingInfoVO> => {
  return request({
    url: '/erp/warehousingInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增入库明细
 * @param data
 */
export const addWarehousingInfo = (data: WarehousingInfoForm) => {
  return request({
    url: '/erp/warehousingInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改入库明细
 * @param data
 */
export const updateWarehousingInfo = (data: WarehousingInfoForm) => {
  return request({
    url: '/erp/warehousingInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除入库明细
 * @param id
 */
export const delWarehousingInfo = (id: string | number | Array<string | number>) => {
  return request({
    url: '/erp/warehousingInfo/' + id,
    method: 'delete'
  });
};
/**
 * 默认标题
 */
export const defaultTitle = () => {
  return request({
    url: `/erp/warehousing/title`,
    method: 'get'
  });
};
/**
 * 审核操作
 * @param url
 * @param data
 */
export const auditWarehousingApi = (data: any) => {
  return request({
    url: `/erp/warehousing/audit`,
    method: 'PUT',
    data
  });
};
